package game;

import hibernateUtil.Playerinfo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import platform.AppConfig;
import protocol.BenefitsType;

/**
 * 
 * @author zhengjiangyu
 * 
 */
public class MakeGold {
	public ArrayList<MakeGoldTimes> listTime;
	/**
	 * 是否可以加成
	 */
	private boolean canAddtion;
	/**
	 * 金币兑换比例
	 */
	private float goldScale;
	/**
	 * 血石兑换比例
	 */
	private float bloodScale;
	/**
	 * 加成数
	 */
	private int numAddtion;
	SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");// 获取的是时分秒毫秒
	// / <summary>
	public MakeGold() {

		listTime = new ArrayList<MakeGoldTimes>();
	}

	public void Start() throws ParseException {
		
		

		String[] strTime = AppConfig.getDicBenefitsInfo()
				.get(BenefitsType.MakeGoldTime).toString().trim().split("[;]",-1);
		String[] myTime = null;
		listTime.clear();
		for (String item : strTime) {

			if (!item.equals("")) {
				myTime = item.split("[,]",-1);
				java.util.Date date = sdf.parse(myTime[0]);
				java.util.Date date1 = sdf.parse(myTime[1]);
				MakeGoldTimes tempTime = new MakeGoldTimes(date, date1);
				listTime.add(tempTime);
			}
		}
		bloodScale = Float.parseFloat(AppConfig.getDicBenefitsInfo()
				.get(BenefitsType.MakeGoldScale).toString().split("[:]",-1)[0]);
		goldScale = Float.parseFloat(AppConfig.getDicBenefitsInfo()
				.get(BenefitsType.MakeGoldScale).toString().split("[:]",-1)[1]);
		numAddtion = Integer.parseInt(AppConfig.getDicBenefitsInfo()
				.get(BenefitsType.MakeGoldAddtion).toString());
	}

	/**
	 * 检测是否在加成时间段内
	 * @throws ParseException 
	 */
	public void AnlasyAddtion() throws ParseException {

		Date nowTime = new Date();
		
		String timeDate=sdf.format(nowTime);
		java.util.Date date = sdf.parse(timeDate);
		for (MakeGoldTimes item : listTime) {
			if (date.after(item.startTime) && date.before(item.endTime)) {
				canAddtion = true;
				return;
			}
		}
		canAddtion = false;
	}

	/**
	 * 可以转换成多少金币
	 */
	public int CanMakeGold(int mNum) {
		
		//加成被取消了
		if (canAddtion) {
			
             return (int)((float)mNum / bloodScale * goldScale * ((numAddtion / 100f + 1f)+(int)(mNum/4f)/10f));

		} else {
			return (int)(((float)mNum / bloodScale * goldScale) * (((int)(mNum / 4f) / 10f)+1f));
		}
	}
	


}
